*===============================================================================
*
*					WORKER BELIEFS ABOUT OUTSIDE OPTIONS
*		(c)	Simon Jaeger, Christopher Roth, Nina Roussille, Benjamin Schoefer
*							  2023 December 5
*						   	   	 Local Data 
*
*===============================================================================


********************************************************************************
*								Figure B06	 								   *
********************************************************************************

clear

*** data preparation 

use "$temp/GSOEPIS_survey_reshaped.dta", clear
keep if fulltime==1 & syear == 19

* winsorize post sample restriction 
foreach var in salary_median salary salary_guess{
	winsor `var', gen(`var'_w2) p(0.02)
}
replace salary_w2 = salary_w2/12
gen l_medguess_own = ln(salary_guess_w2) 
gen l_median_own = ln(salary_median)
gen l_salary_own = ln(salary_w2)

cap drop l_medguess_own_r l_med_own_r
reg l_medguess_own l_salary_own
predict l_medguess_own_r, residuals
reg l_median_own l_salary_own
predict l_med_own_r, residuals

local ytitle "Residual Median (Belief) on Own Wage"
local xtitle "Residual Median (Objective) on Own Wage"

reg   l_medguess_own_r l_med_own_r 
	  local cons = string(round(_b[_cons],0.001),"%7.3f")
	  local beta = string(round(_b[l_med_own_r],0.001),"%7.3f") 
	  local se = string(round(_se[l_med_own_r],0.001),"%7.3f") 
	  local samp = e(N)

preserve
	qui binscatter l_medguess_own_r l_med_own_r, savedata("$temp/binned_l_medguess_own_r") replace
restore

import delimited "$temp/binned_l_medguess_own_r.csv", clear
summ l_med_own_r
local min : di %7.3g `r(min)'
local max : di %7.3g `r(max)'
tempfile temp_data
save `temp_data'

use `temp_data', clear

twoway (lfit l_medguess_own_r l_med_own_r, lc(maroon) mc(maroon) msymbol(O) lpattern(solid) range(-0.6 0.6)) (function y = x, range(-0.6 0.6) color(black%50)) (scatter l_medguess_own_r l_med_own_r , mc(navy)), ytitle("`ytitle'") xtitle("`xtitle'") xlabel(#10, grid)  ylabel(#10, grid) xscale(range(`min' `max')) yscale(range(`min' `max')) legend(order(- "Slope: `beta' (SE `se')") cols(1) ring(0) size(medsmall) position(11) region(lwidth(none))) 
addplot: scatteri 0.35 0.3 "Accurate Beliefs: Slope = 1", msymbol(i) mlabpos(0) mlabcolor(black) mlabangle(34) legend(order(- "Slope: `beta' (SE `se')") cols(1) ring(0) size(medsmall) position(11) region(lwidth(none))) 

graph export "$fig/FigureB06.pdf", replace	

